
var morgan = require("morgan");
var path = require('path');
var fs = require('fs');
var FileStreamRotator = require('file-stream-rotator');


//log config
morgan.token('myParam', function(req, res){

    if(req.method.toUpperCase() == 'GET'){
        return JSON.stringify(req.query);
    }else if(req.method.toUpperCase() == "POST"){
        return JSON.stringify(req.body);
    }
});

morgan.format("myFmt","[my-fmt] :method :url :status :myParam");
var logDirectory = path.join(__dirname, '../log');

fs.existsSync(logDirectory) || fs.mkdirSync(logDirectory);

module.exports.accessLogStream = FileStreamRotator.getStream({

    filename: logDirectory + '/access-%DATE%.log',
    frequency: 'daily',
    verbose: false
});
module.exports.morgan = morgan;
//log config end